package cn.kgc.vue.controller;

import cn.kgc.vue.commons.QueryCondition;
import cn.kgc.vue.commons.ResponseResult;
import cn.kgc.vue.entity.Student;
import cn.kgc.vue.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;

/**
 * @author 课工场
 * @date 2024/7/9
 * @description
 */
@RestController
@RequestMapping("student")
@Api(tags = "学生模块")
public class StudentController {

    @Resource
    private StudentService studentService;

    @PostMapping("page")
    @ApiOperation("学生分页")
    public ResponseResult studentPage(@RequestBody QueryCondition<Student> queryCondition) {

        return studentService.studentPage(queryCondition);
    }


    @PostMapping("add")
    @ApiOperation("新增学生")
    public ResponseResult addStudent(@RequestBody Student student) {

        studentService.save(student);
        return ResponseResult.success().message("学生信息添加成功");
    }

    @PutMapping("edit")
    @ApiOperation("编辑学生")
    public ResponseResult editStudent(@RequestBody Student student) {

        boolean b = studentService.updateById(student);
        if (b) {
            return ResponseResult.success().message("学生信息编辑成功");
        }
        return ResponseResult.fail().message("学生信息编辑失败");
    }

    @DeleteMapping("delete/{id}")
    @ApiOperation("删除学生")
    public ResponseResult deleteStudent(@PathVariable("id") Integer id) {
        studentService.removeById(id);
        return ResponseResult.success().message("学生信息删除成功");
    }

    @PostMapping("import")
    @ApiOperation("批量导入学生信息")
    public ResponseResult importStudent(MultipartFile file) throws Exception {

        return studentService.importStudent(file);
    }


    @PostMapping("export")
    @ApiOperation("批量出学生信息")
    public void   exportStudent(@RequestBody HashMap<String,Object> exportParam, HttpServletResponse response) {
        studentService.exportStudent(exportParam,response);
    }





}
